requireJS(['constant', 'site', 'handlebars', 'public', 'uploadImage', 'static/js/page/common/common.js'], function (Constant, site, Handlebars, Public,UploadImage ,Common ) {
    Public.initApplyTerm();
    Public.initProductSearch();
    Constant.initHandlebars(Handlebars);
    UploadImage.init();
    UploadImage.OSS_IMAGE_INIT();


    var odata = "";

    //全选功能
    $("input[name='ch_id_all']").on('click', function () {
        var _checked = $("input[name='ch_id']")
        if ($(this).prop('checked')) {
            _checked.prop('checked', true)
        }
        else {
            _checked.prop('checked', false)
        }
    })

    //保存订单信息
    var product_id;
    var order_id;
    var taskId;
    var node_type;
    var node_id;
    var last_node_id;
    var s_id;
    var url = {
        queryTk: "manager/queryTk.do",
        queryOrder: 'manager/selectOrderPageList.do',
        queryAdminRoleByRole: "manager/queryAdminRoleByRoleId.do",
        roamTask: "manager/roamTask.do",
        delOrderAll: "manager/delOrderAll.do",
        selectPageLogList: "manager/selectPageLogList.do",
        getActivitiProccessImage: "manager/getActivitiProccessImage.do",

        /***************流程节点自定义表单***********************/
        queryEndNodeId: "manager/queryEndNodeId.do",
        selectLoanTypeList: "manager/selectLoanTypeList.do",
        selectApplyTermList: "manager/selectApplyTermList.do",
        selectOrderSourceList: "manager/selectOrderSourceList.do",
        selectRepanymentWayList: "manager/selectRepanymentWayList.do",
        queryLoanDefineByProductId: "manager/queryLoanDefineByProductId.do",
        selectLoanMethodList: "manager/selectLoanMethodList.do",
        queryNodeFromInfoAllByONid: "manager/queryNodeFromInfoAllByONid.do",
        saveNodefromInfos: "manager/saveNodefromInfos.do",
        backProcess: "manager/backProcess.do",
        ChoiceOfclient: "manager/ChoiceOfclient.do",
        entrustOrder: "manager/entrustOrder.do",

        /***************图片上传*****************/
        insertAttachment: "manager/insertAttachment.do",
        selectAttachmentType: "manager/selectAttachmentTypeproduct.do",
    }


    //用户登录取出缓存的用户登录信息
    var userMessage = {
        roleId: JSON.parse(localStorage.getItem('content')).admin.roleid,
        userId: JSON.parse(localStorage.getItem('content')).admin.id
    }

    //查询产品所需字段
    var frontData = {
        roleId: userMessage.roleId,
        pageNum: 1
    };

    //图片上传所需数组
    var attachImg = new Array();
    var attachimg = new Array();

    //渲染搜索框的贷款方式
    site.send({
        url: url.selectLoanMethodList,
        callback: function (data) {
            data = JSON.parse(data);
            if (data.type == '1') {
                var source = $("#loanMethod_list_tpl").html();
                var template = Handlebars.compile(source);
                var list = data
                var html = template(list)
                $('#loan_way').append(html);
            }
        }
    })

    function saveNodefromInfos() {
        var productInfos = new Array();
        //获取产品自定义真实数据信息
        var td = $(".productInfos").find('td[property_id]');
        $.each(td, function (i, e) {
            var productForm = $(e).find('[productForm]')
            if (productForm.attr('productForm') == 'text') {
                var obj = {
                    property_id: $(e).attr('property_id'),
                    name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    order_id: order_id,
                    value: productForm.val(),
                    record_value: productForm.val()
                }
            }
            if (productForm.attr('productForm') == 'select') {
                var obj = {
                    property_id: $(e).attr('property_id'),
                    name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    order_id: order_id,
                    content_ids: productForm.find('option:selected').val(),
                    value: productForm.find('option:selected').val() ? productForm.find('option:selected').text() : '',
                    record_value: productForm.find('option:selected').val() ? productForm.find('option:selected').text() : ''
                }
            }
            if (productForm.attr('productForm') == 'radio') {
                var content_ids = "";
                var value = "";
                var record_value = "";
                $.each(productForm, function (ii, ee) {
                    if ($(ee).is(":checked")) {
                        content_ids = $(ee).val();
                        value = $(ee).parent('label').text();
                        record_value = $(ee).parent('label').text();
                    }
                })
                var obj = {
                    property_id: $(e).attr('property_id'),
                    name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    order_id: order_id,
                    content_ids: content_ids,
                    value: value,
                    record_value: record_value
                }
            }
            if (productForm.attr('productForm') == 'textarea') {
                var obj = {
                    property_id: $(e).attr('property_id'),
                    name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    order_id: order_id,
                    value: productForm.val(),
                    record_value: productForm.val()
                }
            }
            if (productForm.attr('productForm') == 'checkbox') {
                var content_ids = "";
                var value = "";
                var record_value = "";
                $.each(productForm, function (ii, ee) {
                    if ($(ee).is(":checked")) {
                        content_ids += $(ee).val() + ',';
                        value += $(ee).parent('label').text() + ',';
                        record_value += $(ee).parent('label').text() + ',';
                    }
                })
                content_ids = content_ids.substring(0, content_ids.length - 1)
                value = value.substring(0, value.length - 1)
                record_value = record_value.substring(0, record_value.length - 1)
                var obj = {
                    property_id: $(e).attr('property_id'),
                    name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    order_id: order_id,
                    content_ids: content_ids,
                    value: value,
                    record_value: record_value
                }
            }
            //if (obj.required == '1' || obj.value != '') {
            productInfos.push(obj);
            //}
        })


        var productFeeInfos = new Array();

        var charging = $("input[fee_id]");

        $.each(charging, function (i, e) {
            var obj = {
                fee_id: $(e).attr("fee_id"),
                name: $(e).attr('name'),
                required: $(e).attr('require'),
                order_id: order_id,
                fee: $(e).val(),
                record_value: $(e).val()
            }
            productFeeInfos.push(obj);
        })


        var loanInfos = new Array();

        var loan = $("input[loan_id]:checked");
        if (loan.length) {
            loanInfos.push({
                loan_id: loan.attr("loan_id"),
                order_id: order_id,
                required: '1',
                value: loan.parent('label').text(),
                record_value: loan.parent('label').text()
            })
        }

        var orderInfos = new Array();

        var column = $("[column_key]")
        $.each(column, function (i, e) {
            if ($(e).attr('column_key') == 'loan_way') {
                var value = $(e).find('input[type="radio"]:checked').val();
                var record_value = $(e).find('input[type="radio"]:checked').text();
                var obj = {
                    order_id: order_id,
                    column_key: $(e).attr('column_key'),
                    name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    value: value,
                    record_value: record_value
                }
            }
            else if ($(e).attr('column_key') == 'apply_money') {
                var obj = {
                    order_id: order_id,
                    column_key: $(e).attr('column_key'),
                    name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    value: parseInt(Constant.fn.toNum($(e).val())),
                    record_value: parseInt(Constant.fn.toNum($(e).val())),
                }
            } else if ($(e).attr('column_key') == 'interest') {
                var obj = {
                    order_id: order_id,
                    column_key: $(e).attr('column_key'),
                    name: $(e).attr('name'),
                    fixed_name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    value: $(e).val(),
                    record_value: $(e).val()
                }
            }
            else {
                var option = $(e).find('option:selected');
                var obj = {
                    order_id: order_id,
                    column_key: $(e).attr('column_key'),
                    name: $(e).attr('name'),
                    required: $(e).attr('require'),
                    value: option.data('id') ? option.data('id') : "",
                    record_value:
                        option.text()
                }
            }
            //if (obj.required == '1' || obj.value != '') {
            orderInfos.push(obj);
            //}
        })


        var frontData = {
            productInfos: productInfos,
            productFeeInfos: productFeeInfos,
            orderInfos: orderInfos,
        }

        var productInfos = frontData.productInfos;
        var productFeeInfos = frontData.productFeeInfos;
        var orderInfos = frontData.orderInfos;


        for (var i = 0; i < productInfos.length; i++) {
            if (productInfos[i].required == '1' && !productInfos[i].value) {
                Constant.fn.Message('I', '请填写' + productInfos[i].name);
                return;
            }
        }

        for (var i = 0; i < productFeeInfos.length; i++) {
            if (productFeeInfos[i].required == '1' && !productFeeInfos[i].fee) {
                Constant.fn.Message('I', '请填写' + productFeeInfos[i].name);
                return;
            }
        }

        for (var i = 0; i < orderInfos.length; i++) {
            if (orderInfos[i].required == '1' && !orderInfos[i].value) {
                Constant.fn.Message('I', '请填写' + orderInfos[i].name);
                return;
            }
        }


        //验证是否选择角色
        var userId = $("#role_select option:selected").val();
        var remark = $(".approveRemark").val();
        if (last_node_id != node_id) {
            if (!userId) {
                Constant.fn.Message('I', '请选择审批角色');
                return;
            }
        }
        if (!remark) {
            Constant.fn.Message('I', '请输入备注');
            return;
        }
        ;

        site.send({
            url: url.saveNodefromInfos,
            data: {
                frontData: JSON.stringify(frontData)
            },
            callback: function (data) {
                data = JSON.parse(data)
                if (data.type == 1) {
                    roamTask(userId, remark);
                } else {
                    Constant.fn.Message("T", data.msg);
                }
            }
        })
    }


    //流转
    function roamTask(userId, remark) {
        var data = {
            taskId: taskId,
            userId: userId,
            orderId: order_id,
            remark: remark,
            type: '1'
        }
        site.send({
            url: url.roamTask,
            data: data,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    $('.processForm_winBox').toggle();
                    Constant.fn.Message('T', data.msg);
                    pjaxReload();
                } else {
                    Constant.fn.Message("F", data.msg)
                }
            },
            callError: function () {

            }
        })
    }

    //查询订单表
    function salesManCheck() {
        var data = {
            roleId: Constant.getAurlparam("roleId"),
            audit_status: '',
            pageNum: frontData.pageNum,
            susp_status: '1'
        }
        if ($("#beginTime").val()) {
            data.beginTime = $("#beginTime").val()
        }
        if ($("#endTime").val()) {
            data.endTime = $("#endTime").val()
        }
        if ($("#seleNames option:selected").val()) {
            data.type = $("#seleNames option:selected").val()
        }
        if ($("#inputNames").val()) {
            data.keyword = $("#inputNames").val();
        }
        if ($("#at_id option:selected").val()) {
            data.atId = $("#at_id option:selected").val()
        }
        if ($("#loan_way option:selected").val()) {
            data.loan_way = $("#loan_way option:selected").val()
        }
        if ($("#product_choose_list").val()) {
            data.product_id = $("#product_choose_list").val()
        }
        site.send({
            url: url.queryOrder,
            data: data,
            callback: function (data) {
                if (data && data !== "noLogin") {
                    data = JSON.parse(data)
                    if (data.type == 1) {
                        if (data.content) {
                            $('.order-page-container').createPager({
                                current: frontData.pageNum,
                                total: data.content.total,
                                pageSize: data.content.pageSize,
                                needInput: false,
                                backFn: function (current) {
                                    frontData.pageNum = current;
                                    salesManCheck();
                                }
                            })
                            $('.result').html(data.content.total ? data.content.total : 0);
                        }
                        //handlebars模板引擎
                        var source = $("#order_list_tpl").html()
                        var template = Handlebars.compile(source)
                        var content = data.content;

                        var menuIndex = getAurlparam('h') || 0;
                        var thirdMenusIndex = getAurlparam('t') || 0;
                        var leftIndex = getAurlparam('i') || 0;

                        var storageContent = JSON.parse(localStorage.getItem('content'));

                        var obj = {
                            content: content,
                            fourthMenus: storageContent.menus[menuIndex].children[leftIndex].children[thirdMenusIndex].children || {}
                        }
                        var html = template(obj)
                        $('#order_list').html(html)

                        var source = $("#special_fourth_tpl").html()
                        var template = Handlebars.compile(source)
                        var html = template(storageContent.menus[menuIndex].children[leftIndex].children[thirdMenusIndex].children)
                        $("#orderIn").remove();
                        $('.public-botPage-left').append(html)

                        //复选框一个没选中则全选去除
                        $.each($("input[name='ch_id']"), function (i, e) {
                            var flag = false;
                            $(e).on('click', function () {
                                var _checked = $("input[name='ch_id_all']")
                                var _checkedAll = $("input[name='ch_id']")
                                $.each(_checkedAll, function (ii, ee) {
                                    if ($(ee).prop('checked')) {
                                        flag = true
                                    }
                                    else {
                                        flag = false
                                        return false;
                                    }
                                })
                                _checked.prop('checked', flag);
                            })
                        })

                        //渲染出模板后在进行操作
                        $(".operations").on('change', function () {
                            product_id = $(this).attr('product_id');
                            order_id = $(this).attr('order_id');
                            taskId = $(this).attr('task_id');
                            node_type = $(this).attr('node_type')
                            node_id = $(this).attr('node_id')
                            s_id = $(this).attr('s_id')
                            if ($(this).val() == 'loanBeforeEditOrder') {
                                pjaxGo("loanBefore/orderEdit.html?order_id=" + order_id + "&product_id=" + product_id + "&task_id=" + taskId + "&node_id=" + node_id + "&s_id=" + s_id);
                            }
                            else if ($(this).val() == 'checkOrder') {
                                pjaxGo("loanBefore/orderDetail.html?order_id=" + order_id + "&product_id=" + product_id + "&task_id=" + taskId + "&node_id=" + node_id + "&s_id=" + s_id + "&isSubmit=yes");
                            }
                            else if ($(this).val() == 'submitReview') {
                                if (node_type !== 3) {
                                    $('.formBox .attachment').remove();
                                    $('.formBox .productInfos').remove();
                                    $('.formBox .fix').remove();
                                    $('.processForm_winBox').toggle();
                                    getLastNodeId(product_id)
                                    /*selectAttachmentType(node_id, product_id)
                                    queryNodeForm(order_id, node_id, product_id)*/
                                    queryRole(order_id);
                                }
                            }
                            else if ($(this).val() == 'orderDelegate') {
                                $('.delegate_winBox').toggle();
                                queryDelegate(1);
                            }
                            else if ($(this).val() == 'delApply') {
                                $('.delete_winBox').toggle();

                                odata = order_id;
                            }
                            else if ($(this).val() == 'lookProcess') {
                                $('.processBox').remove()
                                site.send({
                                    url: url.getActivitiProccessImage,
                                    data: {
                                        taskId: taskId,
                                    },
                                    callback: function (data) {
                                        data = JSON.parse(data)
                                        if (data.type == 1) {
                                            var source = $("#process_list_tpl").html();
                                            var template = Handlebars.compile(source);
                                            var list = data.content
                                            var html = template(list)
                                            $('.lookProcess').append(html)
                                            $('.lookProcess_winBox').toggle();
                                        } else {
                                            Constant.fn.Message("F", data.msg);
                                        }
                                    }
                                })
                                //queryDelegate(1);
                            }
                            else if ($(this).val() == 'submitVisit') {
                                Common.visit(order_id);
                                Common.init(3, order_id);
                            }
                            $(this).find("option:first").attr("selected", false).attr("selected", true);
                        });
                        Public.record('t_order_public');
                        //录入订单
                        $("#orderIn").on('click', function () {
                            pjaxGo("loanBefore/product_orderIn.html");
                        })

                    } else {
                        Constant.fn.Message("F", data.msg);
                    }
                }
            },
            callError: function () {
                alert("error")
            }
        })
    }

    //查询出委托人列表
    function queryDelegate(current) {
        site.send({
            url: url.ChoiceOfclient,
            data: {
                pageNum: current
            },
            callback: function (data) {
                data = JSON.parse(data)
                if (data.type == 1) {
                    var source = $("#delegate_role_list_tpl").html();
                    var template = Handlebars.compile(source);
                    var list = data.content
                    var html = template(list)
                    $('.delegate_role_list').html(html)

                    $('.delegate-role-page-container').createPager({
                        current: frontData.pageNum,
                        total: data.content.total,
                        pageSize: data.content.pageSize,
                        needInput: false,
                        backFn: function (current) {
                            queryDelegate(current);
                        }
                    })
                }
                else {
                    Constant.fn.Message("F", data.msg)
                }
            }
        })
    }

    //确认委托
    $("#delegate").on('click', function () {
        var assignee = $(".delegate_role_list input[type='radio']:checked").val();
        if (!assignee) {
            Constant.fn.Message("I", "请选择委托人")
        }
        site.send({
            url: url.entrustOrder,
            data: {
                taskId: taskId,
                assignee: assignee,
                oid: order_id
            },
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == '1') {
                    $('.delegate_winBox').toggle();
                    Constant.fn.Message("T", data.msg)
                    pjaxReload();
                }
                else {
                    Constant.fn.Message("F", data.msg);
                }
            }
        })
    })

    //退回审核弹窗操作
    $('.sureBack').on('click', function () {
        site.send({
            url: url.backProcess,
            data: {
                backParameters: JSON.stringify(arr),
                remark: remark
            },
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    $('.backProcess_winBox').toggle();
                    salesManCheck();
                }
                else {
                    Constant.fn.Message('F', data.msg);
                }
            }
        })
    })

    $('.canBack').on('click', function () {
        $('.backProcess_winBox').toggle();
    })


    /*//节点表单审核单选按钮
    $('input[name="faceResult"][value="1"]').on('click',function(){
        queryRole(order_id);
    })

    $('input[name="faceResult"][value="2"]').on('click',function(){
        $('.assBox2').html('');
    })*/

    //搜索功能
    $(".sousuo").on('click', function () {
        frontData.pageNum = 1;
        salesManCheck();
    })

    //获取流程的最后一个节点，判断是否处在流程最后一步
    function getLastNodeId(product_id) {
        site.send({
            url: url.queryEndNodeId,
            data: {
                product_id: product_id,
            },
            callback: function (data) {
                data = JSON.parse(data)
                if (data.type == 1) {
                    last_node_id = data.content.node_id;
                }
                else {
                    Constant.fn.Message("F", data.msg);
                }
            }
        })
    }


    //点击隐藏
    /*$("#show").on('click', function (e) {
        e.stopPropagation();
        $('.winBox').toggle();
    })*/
    $(document).on('click', '.icon-wrong', function () {
        $(this).parents('.winBox').hide();
    })


    //点击流转
    $("#roamTask").click(function (e) {
        e.stopPropagation();
        saveNodefromInfos();
        //roamtask(userId);
    })

    salesManCheck();

    /*//查询已审核与未审核
        $(".public-List").on('click', function () {
            $('.public-List').removeClass('publicListHover');
            $(this).addClass('publicListHover')
            salesManCheck();
        })*/


    //流转查询出角色
    function queryRole(order_id) {
        site.send({
            url: url.queryAdminRoleByRole,
            data: {
                order_id: order_id
            },
            callback: function (data) {
                data = JSON.parse(data)
                if (data.type == 1) {
                    var source = $("#role_list_tpl").html();
                    var template = Handlebars.compile(source);
                    var list = data.content
                    var html = template(list)
                    $('.assBox2').html(html)


                    //下拉框选中获取值
                    $("#role_select").on('change', function () {
                        userId = $(this).find("option:selected").val();
                    })
                }
                else {
                    var source = $("#role_list_tpl").html();
                    var template = Handlebars.compile(source);
                    var list = data.content
                    var html = template(list)
                    $('.assBox2').html(html)
                    Constant.fn.Message("F", data.msg);
                }
            }
        })
    }


    function initformSelect(content) {
        site.send({
            url: url.selectLoanTypeList,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    var source = $("#loanType_content_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data.content);
                    $('#loanType_content').html(html);

                    var orderInfos = content.orderInfos;
                    $.each(orderInfos, function (i, e) {
                        if (e.fixed_key == "lt_id") {
                            if (e.is_edit == 1) {
                                $("#loanType_content option[data-id=" + e.real_data + "]").attr("selected", true)
                            }
                            else {
                                $("#loanType_content").parents('td').html($("#loanType_content option[data-id=" + e.real_data + "]").text());
                            }
                        }
                    })
                }
                else {
                    Constant.fn.Message("F", data.msg)
                }
            }
        })

        site.send({
            url: url.selectApplyTermList,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    var source = $("#applyTerm_content_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data.content);
                    $('#applyTerm_content').html(html);

                    var orderInfos = content.orderInfos;
                    $.each(orderInfos, function (i, e) {
                        if (e.fixed_key == "at_id") {
                            if (e.is_edit == 1) {
                                $("#applyTerm_content option[data-id=" + e.real_data + "]").attr("selected", true)
                            }
                            else {
                                $("#applyTerm_content").parents('td').html($("#applyTerm_content option[data-id=" + e.real_data + "]").text());
                            }
                        }
                    })
                }
                else {
                    Constant.fn.Message("F", data.msg)
                }
            }
        })

        site.send({
            url: url.selectRepanymentWayList,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    var source = $("#repanymentWay_content_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data.content);
                    $('#repanymentWay_content').html(html);

                    var orderInfos = content.orderInfos;
                    $.each(orderInfos, function (i, e) {
                        if (e.fixed_key == "repayment_way") {
                            if (e.is_edit == 1) {
                                $("#repanymentWay_content option[data-id=" + e.real_data + "]").attr("selected", true)
                            }
                            else {
                                var real_data = $("#repanymentWay_content option[data-id=" + e.real_data + "]").text()
                                real_data ? $("#repanymentWay_content").parents('td').html(real_data) : "未填写";
                            }
                        }
                    })
                }
                else {
                    Constant.fn.Message("F", data.msg)
                }
            }
        })

        site.send({
            url: url.selectOrderSourceList,
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    var source = $("#orderSource_content_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data.content);
                    $('#orderSource_content').html(html);

                    var orderInfos = content.orderInfos;
                    $.each(orderInfos, function (i, e) {
                        if (e.fixed_key == "os_id") {
                            if (e.edit == 1) {
                                $("#orderSource_content option[data-id=" + e.real_data + "]").attr("selected", true)
                            }
                            else {
                                var real_data = $("#orderSource_content option[data-id=" + e.real_data + "]").text()
                                real_data ? $("#orderSource_content").parents('td').html(real_data) : "未填写";
                            }
                        }
                        if (e.fixed_key == "apply_money") {
                            if (e.edit == 1) {
                                $("#apply_money").val(e.real_data);
                            }
                            else {
                                $("#apply_money").parents('td').html(e.real_data + "元");
                            }
                        }
                    })
                }
                else {
                    Constant.fn.Message("F", data.msg)
                }
            }
        })

        site.send({
            url: url.queryLoanDefineByProductId,
            data: {
                product_id: product_id
            },
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    var source = $("#loanMethod_content_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data.content);
                    $('#loanMethod_content').append(html);

                    var orderInfos = content.orderInfos;
                    $.each(orderInfos, function (i, e) {
                        if (e.fixed_key == "loan_way") {
                            if (e.edit == 1) {
                                $("#loanMethod_content input[value=" + e.real_data + "]").prop("checked", true);
                            }
                            else {
                                $("#loanMethod_content input[value=" + e.real_data + "]").prop("checked", true);
                                $("#loanMethod_content").parents('tr').html($('#loanMethod_content input[type="radio"]:checked').text());
                            }
                        }
                    })
                }
                else {
                    Constant.fn.Message("F", data.msg)
                }
            }
        })
    }

    //流转查询出附件类型
    function selectAttachmentType(node_id, product_id) {
        site.send({
            url: url.selectAttachmentType,
            data: {
                productId: product_id,
                nodeId: node_id
            },
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    var source = $("#attachmentType_tpl").html();
                    var template = Handlebars.compile(source);
                    var list = data.content;
                    var html = template(list);
                    $('.formBox .approve').before(html);

                }
            }
        })
    }

    //流转查询出表单
    function queryNodeForm(order_id, node_id, product_id) {
        site.send({
            url: url.queryNodeFromInfoAllByONid,
            data: {
                node_id: node_id,
                order_id: order_id,
                product_id: product_id
            },
            callback: function (data) {
                data = JSON.parse(data);
                if (data.type == 1) {
                    //handlebars模板引擎
                    var source = $("#form_list_tpl").html()
                    var template = Handlebars.compile(source)
                    var content = data.content
                    var html = template(content)
                    $('.formBox .approve').before(html)
                    /*var content = data.content;
                    if(content.productInfos)
                    {
                        $('.formBox').append("<table class=\"resultTab\" style=\"margin: 20px 0px;\"><tbody></tbody></table>")
                        $.each(content.productInfos,function(i,e){
                            if(e.define_type != 'form_name'){
                                $('.resultTab tbody').append('')
                            }
                        })
                    }*/
                    $('#apply_money').on({
                        'focus': function () {
                            $(this).val(Constant.fn.toNum($(this).val()));
                        },
                        'blur': function () {
                            $(this).val(Constant.fn.toRMB($(this).val()));
                        }
                    })

                    //渲染真实数据
                    initformSelect(content);
                }
            }
        })
    }

    //批量操作

    $("#bulk_operation").on('change', function () {
        odata = "";
        var selected = $(this).find("option:selected");
        $(this).find("option:first").prop("selected", false).prop("selected", true);
        $("input[name='ch_id']:checked").each(function (index, item) {
            odata = odata + $(item).val() + ","
        })
        odata = odata.substring(0, odata.length - 1)
        if (selected.val() == '删除') {
            //删除产品
            if (!odata) {
                Constant.fn.Message('I', "未选择要删除的订单")
                return;
            }
            $('.delete_winBox').toggle();
        }
    })

    $('.sureDel').on('click', function () {
        site.send({
            url: url.delOrderAll,
            data: {
                orderIds: odata
            },
            callback: function (data) {
                data = JSON.parse(data)
                if (data.type == 1) {
                    $('.delete_winBox').toggle();
                    Constant.fn.Message('T', data.msg);
                    pjaxReload();
                } else {
                    Constant.fn.Message("F", data.msg)
                }
            },
            callError: function () {

            }
        })
    })

    $('.canDel').on('click', function () {
        $('.delete_winBox').toggle();
    })
    $('.headerIcon').on('click', function () {
        $(this).parents('.delete_winBox').toggle();
    })

    $(".datepicker").datepicker({
        format: 'yyyy-mm-dd',
        autoclose: true
    })


    //左右切换
    /*function pre(key) {
        if($scope.AttaSele[key].left >= 0){
            $scope.AttaSele[key].left = 0
        } else {
            $scope.AttaSele[key].left += 71
        }
    }
    function next(key) {
        if ((274-parseInt($('#gallery'+key).children().css('width'))) >= $scope.AttaSele[key].left){
            $scope.AttaSele[key].left = (274-parseInt($('#gallery'+key).children().css('width')))
        }else{
            $scope.AttaSele[key].left -= 71
        }
    }*/
})

